package test1;
import java.util.Random;
public class Role {
    //前期准备
    //创建对象
    private String name;
    private int age;
    private int blood;
    private char gender;
    private String face;
    private String character;
    //写face和character
    String[] boyfaces = {"清清爽爽", "油油腻腻"};
    String[] girlfaces = {"倾国倾城", "类似东施"};
    String[] characters = {"有耐心", "暴脾气", "双人格"};

    //创建人物
    //封装对象(方法名和类名相同），构造方法
    //空参
    public Role() {

    }

    //有参
    public Role(String name, int age, int blood, char gender) {
        this.blood = blood;
        this.name = name;
        this.age = age;
        this.gender = gender;
        //随机长相
        setFace(gender);
        //随机性格
        setCharacter(character);
    }

    //调用get,set方法
    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setBlood(int blood) {
        this.blood = blood;
    }

    public int getBlood() {
        return blood;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public char getGender() {
        return gender;
    }

    public void setFace(char gender) {
        Random r = new Random();
        if (gender == '男') {
            int index = r.nextInt(boyfaces.length);
            this.face = boyfaces[index];
        } else if (gender == '女') {
            int index = r.nextInt(girlfaces.length);
            this.face = girlfaces[index];
        } else {
            this.face = "奇奇怪怪";
        }
    }

    public String getFace() {
        return face;
    }

    public void setCharacter(String character) {
        Random r = new Random();
        int chara = r.nextInt(characters.length);
        this.character=characters[chara];
    }

    public String getCharacter() {
        return character;
    }

    //介绍游戏规则
    public void rule() {
        System.out.println("先输入比赛双方的属性，接着双方遵守武道，交替对对方进行攻击，直到有一方的血量为0");
        System.out.println("准备好了吗？让我们进入激动人心的擂台吧！");
    }

    //介绍人物信息
    public void roleInfo() {
        System.out.println("姓名：" + getName());
        System.out.println("年龄：" + getAge());
        System.out.println("性别：" + getGender());
        System.out.println("血量：" + getBlood());
        System.out.println("长相：" + getFace());
        System.out.println("性格：" + getCharacter());
    }

    //开始游戏
    //r1先攻击r2
    public void attack(Role role) {
        //计算造成的伤害
        Random r = new Random();
        int hurt = r.nextInt(30) + 1;
        //计算剩余血量
        int remainBlood = role.getBlood() - hurt;
        //判断剩余血量
        remainBlood = remainBlood < 0 ? 0 : remainBlood;
        if (remainBlood < 30) {
            System.out.println(getName() + "危险");
        }
        //修改挨揍人的血量
        role.setBlood(remainBlood);
        System.out.println(this.name + "打了" + role.getName() + "一下，造成了" + hurt + "点伤害，还剩" + remainBlood + "滴血");
    }
}
